package com.tiancheng.trade.authserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiancheng.trade.authserver.entity.UserThirdInfo;
import com.tiancheng.trade.authserver.enums.ThirdPlatformEnums;
import com.tiancheng.trade.authserver.mapper.UserThirdInfoMapper;
import com.tiancheng.trade.authserver.service.IUserThirdInfoService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: likailun
 * @Description: 第三方应用登录servie实现
 * @Date: create in 2024/10/21 17:21
 */
@Service
public class UserThirdInfoServiceImpl extends ServiceImpl<UserThirdInfoMapper, UserThirdInfo> implements IUserThirdInfoService {
    @Override
    public UserThirdInfo getByClientIdAndUserId(ThirdPlatformEnums platform, String clientId, Long userId) {
        final List<UserThirdInfo> list = this.list(new LambdaQueryWrapper<UserThirdInfo>().eq(UserThirdInfo::getPlatform, platform.name())
                .eq(UserThirdInfo::getClientId, clientId).eq(UserThirdInfo::getUserId, userId));
        return CollectionUtils.isNotEmpty(list)?list.get(0):null;
    }

    @Override
    public List<UserThirdInfo> getByUserId(Long userId) {
        return this.list(new LambdaQueryWrapper<UserThirdInfo>().eq(UserThirdInfo::getUserId, userId));
    }
}
